package com.jfinal.controller;

import com.jfinal.aop.Clear;
import com.jfinal.constant.Const;
import com.jfinal.core.Controller;
import com.jfinal.model.auth.Auth;
import com.jfinal.plugin.ehcache.CacheKit;
import com.jfinal.utils.AuthUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by xiaoyuan on 2018/1/20.
 */
@Clear
public class HomeController extends Controller {
    //转到首页
    public void index(){
        //获取当前用户所有的角色
        String roleIds = getSessionAttr(Const.SESSION_ROLES_ID);
        List<Auth> topMenu = new ArrayList<>();
        List<Auth> leftMenu = new ArrayList<>();
        if(roleIds!=null){
            //String[] roles = roleIds.split(",");
            topMenu = AuthUtils.getChildAuth(roleIds,null,Const.TYPE_MENU);
            if(topMenu!=null&&topMenu.size()>0){
                leftMenu =  AuthUtils.getChildAuth(roleIds,topMenu.get(0).getLong("id"),Const.TYPE_MENU);
            }
        }
        setAttr("topMenu",topMenu);
        setAttr("leftMenu",leftMenu);
        renderJsp("home.jsp");
    }
}
